package com.cncrowd.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import com.cncrowd.model.User;

@Controller
public class LoginController {
	@RequestMapping("/register.do")
	public String register (HttpServletRequest req, HttpServletResponse resp,String name, ModelMap map){
		return "register";
	}
		
	@RequestMapping("/login.do")
	public String login (HttpServletRequest req, HttpServletResponse resp,User user,HttpSession session){
		if ("xianming".equals(user.getUsername()) && "password".equals(user.getPassword())){
			session.setAttribute("user", user);
			return "redirect:/home.do";	
		}
		return "login";
	}
	
	@RequestMapping("/home.do")
	public String home (HttpServletRequest req, HttpServletResponse resp,User user,HttpSession session){
		return "home";
	}
	@RequestMapping("/index.do")
	public String index (HttpServletRequest req, HttpServletResponse resp,String name, ModelMap map){
		return "index";
	}
}
